/**
* Author: CZ (cz.devnet@gmail.com)
*
* func main()
 */

package main

import (
	"encoding/json"
	"fmt"
	"os"
)

//ConfigJSONWrapper ConfigJsonWrapper
type ConfigJSONWrapper struct {
	URL   string
	Timer int
}

//LoadConfig load configure
func LoadConfig(filePath string) (err error) {
	fp, err := os.Open(filePath)
	if err != nil {
		fmt.Errorf("Open Config file %s error: %s", filePath, err.Error())
		return
	}
	defer fp.Close()

	var configWrapper ConfigJSONWrapper
	decoder := json.NewDecoder(fp)
	if err = decoder.Decode(&configWrapper); err != nil {
		fmt.Errorf("Decode Config Error:%s", err.Error())
		return
	}
	config.URL = configWrapper.URL
	fmt.Printf("Load Config file %s Success\n", filePath)
	err = nil
	return
}
